//==============================================================================
// TF Audio Settings Page - so the menu music doesn't go back to default
//==============================================================================
class Tab_TaskforcesAudioSettings extends UT2k4Tab_AudioSettings;

function InternalOnLoadINI(GUIComponent Sender, string s)
{
	local int i;
	local PlayerController PC;
	local bool bIsWin32;

	PC = PlayerOwner();

	switch (Sender)
	{
	case sl_VoiceVol:
		iVoice = PC.AnnouncerVolume;
     	sl_VoiceVol.SetComponentValue(iVoice,true);
		break;

	case sl_MusicVol:
		fMusic = float(PC.ConsoleCommand("get ini:Engine.Engine.AudioDevice MusicVolume"));
		sl_MusicVol.SetComponentValue(fMusic,true);
		break;

	case sl_EffectsVol:
		fEffects = float(PC.ConsoleCommand("get ini:Engine.Engine.AudioDevice SoundVolume"));
		sl_EffectsVol.SetComponentValue(fEffects,true);
		break;
/*
	case sl_TTS:
		fTTS = PC.TextToSpeechVoiceVolume;
		sl_TTS.SetComponentValue(fTTS,true);
		break;
*/
	case co_Mode:
		iMode = 1;
		bIsWin32 = ( ( PlatformIsWindows() ) && ( !PlatformIs64Bit() ) );
		if ( !bIsWin32 )
		{
			bCompat = False;
			b3DSound = True;
			iMode = 0;
		}
		else
		{
			if ( bool(PC.ConsoleCommand("get ini:Engine.Engine.AudioDevice CompatibilityMode")) )
			{
				bCompat = True;
				iMode = 0;
			}

			if ( bool(PC.ConsoleCommand("get ini:Engine.Engine.AudioDevice Use3DSound")) )
			{
				b3DSound = True;
				iMode = 2;
			}

			if ( bool(PC.ConsoleCommand("get ini:Engine.Engine.AudioDevice UseEAX" )) )
			{
				bEAX = True;
				iMode = 3;
			}
		}
		co_Mode.SilentSetIndex(iMode);
		break;

	case ch_ReverseStereo:
		bRev = bool(PC.ConsoleCommand("get ini:Engine.Engine.AudioDevice ReverseStereo"));
		ch_ReverseStereo.SetComponentValue(bRev,true);
		break;

	case ch_Default:
		bDefault = bool(PC.ConsoleCommand("get ini:Engine.Engine.AudioDevice UseDefaultDriver"));
		ch_Default.SetComponentValue(bDefault,true);
		break;

	case co_Voices:
		if ( PC.bNoAutoTaunts ) iVoiceMode = 1;
		if ( PC.bNoVoiceTaunts ) iVoiceMode = 2;
		if ( PC.bNoVoiceMessages ) iVoiceMode = 3;
		co_Voices.SilentSetIndex(iVoiceMode);
		break;

	case ch_MessageBeep:
		bBeep = class'HUD'.default.bMessageBeep;
		ch_MessageBeep.SetComponentValue(bBeep,true);
		break;

	case ch_AutoTaunt:
		bAuto = PC.bAutoTaunt;
		ch_AutoTaunt.SetComponentValue(bAuto,true);
		break;

	case ch_TTS:
		bTTS = !PC.bNoTextToSpeechVoiceMessages;
		ch_TTS.SetComponentValue(bTTS,true);
		break;

	case ch_OnlyTeamTTS:
		bOnlyTeamTTS = PC.bOnlySpeakTeamText;
		ch_OnlyTeamTTs.SetComponentValue(bOnlyTeamTTS,True);
		break;

	case ch_MatureTaunts:
		bMature = !PC.bNoMatureLanguage;
		ch_MatureTaunts.SetComponentValue(bMature,true);
		break;

	case ch_LowDetail:
		bLow = PC.Level.bLowSoundDetail;

		// Make sure both are the same - LevelInfo.bLowSoundDetail take priority
		if ( bLow != bool(PC.ConsoleCommand("get ini:Engine.Engine.AudioDevice LowQualitySound" )) )
		{
			PC.ConsoleCommand("set ini:Engine.Engine.AudioDevice LowQualitySound"@bLow);
			PC.ConsoleCommand("SOUND_REBOOT");

			// Restart music.
			if( PC.Level.Song != "" && PC.Level.Song != "None" )
				PC.ClientSetMusic( PC.Level.Song, MTRAN_Instant );

			else PC.ClientSetMusic( class'TFMainMenu'.default.MenuSong, MTRAN_Instant );
		}

		ch_LowDetail.SetComponentValue(bLow,true);
		break;

	case co_Announce:
		iAnnounce = PC.AnnouncerLevel;
		co_Announce.SilentSetIndex(iAnnounce);
		break;

	case co_RewardAnnouncer:

		if ( PC.IsA('UnrealPlayer') )
		{
			sStatAnnouncer = PC.GetCustomStatusAnnouncerClass();
			sRewAnnouncer = PC.GetCustomRewardAnnouncerClass();
		}
		else
		{
			sStatAnnouncer = class'UnrealPlayer'.default.CustomStatusAnnouncerPack;
			sRewAnnouncer = class'UnrealPlayer'.default.CustomRewardAnnouncerPack;
		}

		i = FindAnnouncerClassIndex(sStatAnnouncer);
		if ( i != -1 )
		{
			i = co_StatusAnnouncer.FindIndex(Announcers[i].FriendlyName);
			if ( i != -1 )
				co_StatusAnnouncer.SilentSetIndex(i);
		}

		i = FindAnnouncerClassIndex(sRewAnnouncer);
		if (i != -1)
		{
			i = co_RewardAnnouncer.FindIndex(Announcers[i].FriendlyName);
			if ( i != -1 )
				co_RewardAnnouncer.SilentSetIndex(i);
		}

		break;

	case ch_TTSIRC:
		bTTSIRC = class'UT2K4IRC_Page'.default.bIRCTextToSpeechEnabled;
		ch_TTSIRC.SetComponentValue(bTTSIRC,true);
		break;

	case ch_VoiceChat:
		bVoiceChat = bool(PC.ConsoleCommand("get ini:Engine.Engine.AudioDevice UseVoIP"));
		ch_VoiceChat.SetComponentValue(bVoiceChat,true);
		break;

	default:
		log(Name@"Unknown component calling LoadINI:"$ GUIMenuOption(Sender).Caption);
		GUIMenuOption(Sender).SetComponentValue(s,true);
	}
}

function InternalOnChange(GUIComponent Sender)
{
	local PlayerController PC;
	local float AnnouncerVol;
	local Sound snd;
	local int AnnouncerIdx;
	local bool bIsWin32;

	bIsWin32 = ( ( PlatformIsWindows() ) && ( !PlatformIs64Bit() ) );

	Super.InternalOnChange(Sender);
	PC = PlayerOwner();

	switch(Sender)
	{
		case sl_VoiceVol:
			iVoice = sl_VoiceVol.GetValue();
			AnnouncerVol = 2.0 * FClamp(0.1 + iVoice*0.225,0.2,1.0);
			if ( co_StatusAnnouncer == None )
				return;

			snd = sound(co_StatusAnnouncer.GetObject());
			if ( snd == None && Announcers.Length > 0 )
			{
				snd = Sound(DynamicLoadObject(Announcers[AnnouncerIdx].PackageName $ "." $ StatusPreviewSound,class'Sound'));
				if ( snd == none )
					snd = Sound(DynamicLoadObject(Announcers[AnnouncerIdx].FallbackPackage $ "." $ StatusPreviewSound,class'Sound'));

				co_StatusAnnouncer.MyComboBox.List.SetObjectAtIndex(co_StatusAnnouncer.MyComboBox.List.Index,snd);
			}

			if ( snd != None )
				PC.PlaySound(snd,SLOT_Talk,AnnouncerVol);

			break;

		case sl_MusicVol:
			fMusic = sl_MusicVol.GetValue();
			PC.ConsoleCommand("set ini:Engine.Engine.AudioDevice MusicVolume"@fMusic);
			PC.ConsoleCommand("SetMusicVolume"@fMusic);

			if( PC.Level.Song != "" && PC.Level.Song != "None" )
				PC.ClientSetMusic( PC.Level.Song, MTRAN_Instant );
			else PC.ClientSetMusic( class'TFMainMenu'.default.MenuSong, MTRAN_Instant );
			break;

		case sl_EffectsVol:
			fEffects = sl_EffectsVol.GetValue();
			PC.ConsoleCommand("set ini:Engine.Engine.AudioDevice SoundVolume"@fEffects);
			PC.ConsoleCommand("stopsounds");
			PC.PlaySound(sound'PickupSounds.AdrenelinPickup');
			break;
/*
		case sl_TTS:
			fTTS = sl_TTS.GetValue();
		// Do not preview TTS voice volume, since there isn't any way to truly represent the way it will sound in-game
//				PC.TextToSpeech( "Fo Shizzle my nizzle", fTTS );
			break;
*/
		case co_Mode:
			if ( !bIsWin32 )  // Simple OpenAL abstraction...  --ryan.
				break;

			iMode = co_Mode.GetIndex();
			if (iMode > 1)
				ShowPerformanceWarning();

			bCompat = iMode < 1;
			b3DSound = iMode > 1;
			bEAX = iMode > 2;
	        PC.ConsoleCommand("set ini:Engine.Engine.AudioDevice CompatibilityMode"@bCompat);
	        PC.ConsoleCommand("set ini:Engine.Engine.AudioDevice Use3DSound"@b3DSound);
	        PC.ConsoleCommand("set ini:Engine.Engine.AudioDevice UseEAX"@bEAX);
			PC.ConsoleCommand("SOUND_REBOOT");

			// Restart music.
			if( PC.Level.Song != "" && PC.Level.Song != "None" )
				PC.ClientSetMusic( PC.Level.Song, MTRAN_Instant );
			else PC.ClientSetMusic( class'TFMainMenu'.default.MenuSong, MTRAN_Instant );
			break;

		case ch_ReverseStereo:
			bRev = ch_ReverseStereo.IsChecked();
			break;

		case ch_MessageBeep:
			bBeep = ch_MessageBeep.IsChecked();
			break;

		case ch_AutoTaunt:
			bAuto = ch_AutoTaunt.IsChecked();
			break;

		case ch_TTS:
			bTTS = ch_TTS.IsChecked();
			break;

		case ch_MatureTaunts:
			bMature = ch_MatureTaunts.IsChecked();
			break;

		case co_Voices:
			iVoiceMode = co_Voices.GetIndex();
			break;

		case ch_Default:
			bDefault = ch_Default.IsChecked();
			PC.ConsoleCommand("set ini:Engine.Engine.AudioDevice UseDefaultDriver"@bDefault);
			PC.ConsoleCommand("SOUND_REBOOT");
			break;

		case ch_LowDetail:
			bLow = ch_LowDetail.IsChecked();

			PC.Level.bLowSoundDetail = bLow;
			PC.Level.StaticSaveConfig();

			PC.ConsoleCommand("set ini:Engine.Engine.AudioDevice LowQualitySound"@bLow);
			PC.ConsoleCommand("SOUND_REBOOT");

			// Restart music.
			if( PC.Level.Song != "" && PC.Level.Song != "None" )
				PC.ClientSetMusic( PC.Level.Song, MTRAN_Instant );
			else PC.ClientSetMusic( class'TFMainMenu'.default.MenuSong, MTRAN_Instant );
			break;

		case co_Announce:
			iAnnounce = co_Announce.GetIndex();
			break;

		case co_RewardAnnouncer:
			AnnouncerIdx = int(co_RewardAnnouncer.GetExtra());
			sRewAnnouncer = Announcers[AnnouncerIdx].ClassName;

			AnnouncerVol = 2.0 * FClamp(0.1 + iVoice*0.225,0.2,1.0);
			snd = sound(co_RewardAnnouncer.GetObject());
			if ( snd == None )
			{
				snd = Sound(DynamicLoadObject(Announcers[AnnouncerIdx].PackageName $ "." $ RewardPreviewSound,class'Sound'));
				if ( snd == none )
					snd = Sound(DynamicLoadObject(Announcers[AnnouncerIdx].FallbackPackage $ "." $ RewardPreviewSound,class'Sound'));

				co_RewardAnnouncer.MyComboBox.List.SetObjectAtIndex(co_RewardAnnouncer.MyComboBox.List.Index,snd);
			}
			PC.PlaySound(snd,SLOT_Talk,AnnouncerVol);
			break;

		case co_StatusAnnouncer:
			AnnouncerIdx = int(co_StatusAnnouncer.GetExtra());
			sStatAnnouncer = Announcers[AnnouncerIdx].ClassName;

			AnnouncerVol = 2.0 * FClamp(0.1 + iVoice*0.225,0.2,1.0);
			snd = sound(co_StatusAnnouncer.GetObject());
			if ( snd == None )
			{
				snd = Sound(DynamicLoadObject(Announcers[AnnouncerIdx].PackageName $ "." $ StatusPreviewSound,class'Sound'));
				if ( snd == none )
					snd = Sound(DynamicLoadObject(Announcers[AnnouncerIdx].FallbackPackage $ "." $ StatusPreviewSound,class'Sound'));

				co_StatusAnnouncer.MyComboBox.List.SetObjectAtIndex(co_StatusAnnouncer.MyComboBox.List.Index,snd);
			}
			PC.PlaySound(snd,SLOT_Talk,AnnouncerVol);
			break;

		case ch_TTSIRC:
			bTTSIRC = ch_TTSIRC.IsChecked();
			break;

		case ch_VoiceChat:
			bVoiceChat = ch_VoiceChat.IsChecked();
			break;

		case ch_OnlyTeamTTS:
			bOnlyTeamTTS = ch_OnlyTeamTTS.IsChecked();
			break;
	}
}

DefaultProperties
{

}


